package com.wanggsx.pluginlib;

import android.app.ActionBar;
import android.app.Activity;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Looper;
import android.transition.Scene;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import java.io.File;
import java.util.concurrent.Executor;

/** 被插件activity继承的父Activity类 */
public abstract class PluginActivity extends Activity implements IPlugin {
    private boolean mFalse = true;
    //代理对象的上下文对象
    protected Activity mProxyActivity;

    /** 此处将传入代理activity */
    @Override
    public void attach(Activity activity) {
        mProxyActivity = activity;
        mFalse = false;
    }

    @Override
    public void setContentView(int layoutResID) {
        if (mFalse){
            super.setContentView(layoutResID);
        }else{
            mProxyActivity.setContentView(layoutResID);
        }
    }

    @Override
    public void onStart() {
        if (mFalse){
            super.onStart();
        }
    }

    @Override
    public void onRestart() {
        if (mFalse){
            super.onRestart();
        }
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {

    }

    @Override
    public void onResume() {
        if (mFalse){
            super.onResume();
        }
    }

    @Override
    public void onPause() {
        if (mFalse){
            super.onPause();
        }
    }

    @Override
    public void onStop() {
        if (mFalse){
            super.onStop();
        }
    }

    @Override
    public void onDestroy() {
        if (mFalse){
            super.onDestroy();
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        if (mFalse){
            super.onCreate(savedInstanceState);
        }
    }

    @Override
    public void setProxy(Activity proxyActivity, String dexPath) {

    }

    @Override
    public void onSaveInstanceState(Bundle outState) {

    }

    @Override
    public void onNewIntent(Intent intent) {

    }

    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {

    }

    @Override
    public void onWindowAttributesChanged(ViewGroup.LayoutParams params) {

    }

    public Window getWindow() {
        if (mFalse){
           return super.getWindow();
        }
        else{
            return mProxyActivity.getWindow();
        }
    }

    @Override
    public ClassLoader getClassLoader() {
        if (mFalse){
            return super.getClassLoader();
        }
        else{
            return mProxyActivity.getClassLoader();
        }
    }

    @Override
    public AssetManager getAssets() {
        if (mFalse){
            return super.getAssets();
        }
        else{
            return mProxyActivity.getAssets();
        }
    }

    @Override
    public Resources getResources() {
        if (mFalse){
            return super.getResources();
        }
        else{
            return mProxyActivity.getResources();
        }
    }

    @Override
    public ActionBar getActionBar() {
        if (mFalse){
            return super.getActionBar();
        }
        else{
            return mProxyActivity.getActionBar();
        }
    }

    @Override
    public ApplicationInfo getApplicationInfo() {
        if (mFalse){
            return super.getApplicationInfo();
        }
        else{
            return mProxyActivity.getApplicationInfo();
        }
    }

    @Override
    public ComponentName getCallingActivity() {
        if (mFalse){
            return super.getCallingActivity();
        }
        else{
            return mProxyActivity.getCallingActivity();
        }
    }

    @Override
    public ComponentName getComponentName() {
        if (mFalse){
            return super.getComponentName();
        }
        else{
            return mProxyActivity.getComponentName();
        }
    }

    @Override
    public ContentResolver getContentResolver() {
        if (mFalse){
            return super.getContentResolver();
        }
        else{
            return mProxyActivity.getContentResolver();
        }
    }

    @Override
    public Context getBaseContext() {
        if (mFalse){
            return super.getBaseContext();
        }
        else{
            return mProxyActivity.getBaseContext();
        }
    }

    @Override
    public Context getApplicationContext() {
        if (mFalse){
            return super.getApplicationContext();
        }
        else{
            return mProxyActivity.getApplicationContext();
        }
    }

    @Override
    public File getCacheDir() {
        if (mFalse){
            return super.getCacheDir();
        }
        else{
            return mProxyActivity.getCacheDir();
        }
    }

    @Override
    public Intent getIntent() {
        if (mFalse){
            return super.getIntent();
        }
        else{
            return mProxyActivity.getIntent();
        }
    }

    @Override
    public Looper getMainLooper() {
        if (mFalse){
            return super.getMainLooper();
        }
        else{
            return mProxyActivity.getMainLooper();
        }
    }

    @Override
    public int getChangingConfigurations() {
        if (mFalse){
            return super.getChangingConfigurations();
        }
        else{
            return mProxyActivity.getChangingConfigurations();
        }
    }

    @Override
    public WindowManager getWindowManager() {
        if (mFalse){
            return super.getWindowManager();
        }
        else{
            return mProxyActivity.getWindowManager();
        }
    }

    @Override
    public Resources.Theme getTheme() {
        if (mFalse){
            return super.getTheme();
        }
        else{
            return mProxyActivity.getTheme();
        }
    }

    @Override
    public String getPackageResourcePath() {
        if (mFalse){
            return super.getPackageResourcePath();
        }
        else{
            return mProxyActivity.getPackageResourcePath();
        }
    }

    @Override
    public String getPackageName() {
        if (mFalse){
            return super.getPackageName();
        }
        else{
            return mProxyActivity.getPackageName();
        }
    }

    @Override
    public String getCallingPackage() {
        if (mFalse){
            return super.getCallingPackage();
        }
        else{
            return mProxyActivity.getCallingPackage();
        }
    }

    @Override
    public Object getSystemService(String name) {
        if (mFalse) {
            return super.getSystemService(name);
        } else {
            return mProxyActivity.getSystemService(name);
        }
    }
}
